home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 6 / Test / Main.cpp next >
Encoding:
C/C++ Source or Header  |  2004-07-20  |  3.1 KB  |  91 lines

  1. //-----------------------------------------------------------------------------
  2. // System Includes
  3. //-----------------------------------------------------------------------------
  4. #include <windows.h>
  5.  
  6. //-----------------------------------------------------------------------------
  7. // Engine Includes
  8. //-----------------------------------------------------------------------------
  9. #include "..\Engine\Engine.h"
  10.  
  11. //-----------------------------------------------------------------------------
  12. // Test State Class
  13. //-----------------------------------------------------------------------------
  14. class TestState : public State
  15. {
  16. public:
  17.     //-------------------------------------------------------------------------
  18.     // Allows the test state to preform any pre-processing construction.
  19.     //-------------------------------------------------------------------------
  20.     virtual void Load()
  21.     {
  22.         m_font = new Font;
  23.  
  24.         m_sound = new Sound( "./Assets/Sound.wav" );
  25.     }
  26.  
  27.     //-------------------------------------------------------------------------
  28.     // Allows the test state to preform any post-processing destruction.
  29.     //-------------------------------------------------------------------------
  30.     virtual void Close()
  31.     {
  32.         SAFE_DELETE( m_font );
  33.  
  34.         SAFE_DELETE( m_sound );
  35.     }
  36.  
  37.     //-------------------------------------------------------------------------
  38.     // Returns the view setup details for the given frame.
  39.     //-------------------------------------------------------------------------
  40.     virtual void RequestViewer( ViewerSetup *viewer )
  41.     {
  42.         viewer->viewClearFlags = D3DCLEAR_TARGET;
  43.     }
  44.  
  45.     //-------------------------------------------------------------------------
  46.     // Updates the state.
  47.     //-------------------------------------------------------------------------
  48.     virtual void Update( float elapsed )
  49.     {
  50.         if( g_engine->GetInput()->GetKeyPress( DIK_SPACE ) )
  51.             m_sound->Play();
  52.     }
  53.  
  54.     //-------------------------------------------------------------------------
  55.     // Renders the state.
  56.     //-------------------------------------------------------------------------
  57.     virtual void Render()
  58.     {
  59.         m_font->Render( "Press the space bar to test the sound system.", 10, 10 );
  60.     }
  61.  
  62. private:
  63.     Font *m_font; // A font used to render text.
  64.     Sound *m_sound; // The test sound.
  65. };
  66.  
  67. //-----------------------------------------------------------------------------
  68. // Application specific state setup.
  69. //-----------------------------------------------------------------------------
  70. void StateSetup()
  71. {
  72.     g_engine->AddState( new TestState, true );
  73. }
  74.  
  75. //-----------------------------------------------------------------------------
  76. // Entry point for the application.
  77. //-----------------------------------------------------------------------------
  78. int WINAPI WinMain( HINSTANCE instance, HINSTANCE prev, LPSTR cmdLine, int cmdShow )
  79. {
  80.     // Create the engine setup structure.
  81.     EngineSetup setup;
  82.     setup.instance = instance;
  83.     setup.name = "Sound Test";
  84.     setup.StateSetup = StateSetup;
  85.  
  86.     // Create the engine (using the setup structure), then run it.
  87.     new Engine( &setup );
  88.     g_engine->Run();
  89.  
  90.     return true;
  91. }